home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / iqb9107.zip / READMCBS.BAS < prev   
BASIC Source File  |  1991-06-27  |  3KB  |  130 lines

  1. ' ReadMCBs.Bas
  2. ' Program to display the DOS memory control block chain
  3.  
  4. ' $INCLUDE: 'QB.BI'
  5.  
  6. CONST FALSE = 0, TRUE = NOT FALSE
  7.  
  8. DECLARE SUB GetFirstMCB ()
  9. DECLARE SUB GetNextMCB ()
  10. DECLARE SUB PrintOwnerName ()
  11. DECLARE FUNCTION LZPadStr$ (N$, pLen%)
  12.  
  13. DIM SHARED Regs AS RegTypeX
  14. DIM SHARED MCBSeg AS SINGLE
  15. DIM SHARED ReservedStuff%(11)
  16.  
  17. ' Get the PSP address of the program running
  18. ' (If you're running this in the environment, then the PSP
  19. '  belongs to QB; if you've compiled ReadMCBs, then it's
  20. '  ReadMCBs' PSP.
  21.  
  22. Regs.ax = &H5100
  23. InterruptX &H21, Regs, Regs
  24. PSP% = Regs.bx
  25.  
  26. PRINT "The PSP of this program is "; HEX$(PSP%)
  27. PRINT
  28. PRINT " Segment   owner  Size"
  29. PRINT " Address    PSP   par.  Reserved Area";
  30. PRINT "                    Name"
  31. PRINT "---------  -----  ----  --------------------------------";
  32. PRINT " --------"
  33.  
  34. GetFirstMCB 
  35.  
  36. ' Loop through the memory control blocks,
  37. ' printing out detail for each
  38.  
  39. DO WHILE MCBSeg <> 0
  40.   GetNextMCB
  41. LOOP
  42.  
  43. PRINT "---------  -----  ----  --------------------------------";
  44. PRINT " --------"
  45.  
  46. ' All done
  47.  
  48. END
  49.  
  50.  
  51. SUB GetFirstMCB
  52.  
  53. ' Subprogram to get the segment address of the first
  54. ' memory control block, using the undocumented DOS
  55. ' function GetListOfLists (Int 21h, AH = 52h)
  56.  
  57.   Regs.ax = &H5200
  58.   InterruptX &H21, Regs, Regs
  59.  
  60.   MCBPtrSeg% = Regs.es
  61.   MCBPtrOff% = Regs.bx - 2
  62.  
  63.   DEF SEG = MCBPtrSeg%
  64.   MCBSeg = PEEK(MCBPtrOff%) + PEEK(MCBPtrOff% + 1) * 256!
  65.   DEF SEG
  66. END SUB
  67.  
  68.  
  69. SUB GetNextMCB
  70.  
  71. ' Subprogram to get the segment address of the next
  72. ' memory control block, and print out its detail.
  73.  
  74.   Marker% = 0
  75.   Owner = 0
  76.   Size = 0
  77.   DEF SEG = MCBSeg
  78.   Marker% = PEEK(0)
  79.   Owner = PEEK(1) + PEEK(2) * 256!
  80.   Size = PEEK(3) + PEEK(4) * 256!
  81.   FOR I% = 1 TO 11
  82.      ReservedStuff%(I%) = PEEK(4 + I%)
  83.   NEXT I%
  84.   DEF SEG
  85.   Marker$ = CHR$(Marker%)
  86.   PRINT LZPadStr$(HEX$(MCBSeg), 4); ":0000  ";
  87.   PRINT LZPadStr$(HEX$(Owner), 4); "   ";
  88.   PRINT LZPadStr$(HEX$(Size), 4); "  ";
  89.   FOR I% = 1 TO 11
  90.      PRINT LZPadStr$(HEX$(ReservedStuff%(I%)), 2); " ";
  91.   NEXT I%
  92.   IF MCBSeg < Owner AND MCBSeg + Size > Owner THEN
  93.     PrintOwnerName
  94.   END IF
  95.   IF Marker$ = "M" THEN MCBSeg = MCBSeg + (Size + 1)
  96.   IF Marker$ = "Z" OR Marker$ <> "M" THEN MCBSeg = 0
  97.   IF Marker$ <> "M" AND Marker$ <> "Z" THEN
  98.     PRINT " Memory chain error!!"
  99.   ELSE
  100.     PRINT ""
  101.   END IF
  102. END SUB
  103.  
  104.  
  105. SUB PrintOwnerName
  106.  
  107. ' Subroutine to print the MCB owner's name
  108.  
  109. GotName% = FALSE
  110. J% = 0
  111. Owner$ = ""
  112. WHILE NOT GotName%
  113.    J% = J% + 1
  114.    Ch% = ReservedStuff%(3 + J%)
  115.    IF Ch% = 0 THEN GotName% = TRUE
  116.    IF NOT GotName% THEN Owner$ = Owner$ + CHR$(Ch%)
  117.    IF J% = 8 THEN GotName% = TRUE
  118. WEND
  119. PRINT Owner$;
  120. END SUB
  121.  
  122.  
  123. FUNCTION LZPadStr$ (N$, pLen%)
  124.  
  125. ' Function to return a copy of the numeric string N$,
  126. ' padded on the left with pLen% zeroes.
  127.  
  128.  LZPadStr$ = STRING$(pLen% - LEN(N$), "0") + N$
  129. END FUNCTION
  130.